package com.appshelves.model;

import java.util.EnumSet;
import java.util.List;

import com.appshelves.model.Model.Event;
import com.appshelves.model.Model.EventListener;

class ModelEvents extends ModelAPI {

    private static ModelEvents _instance;

    private EventGenerator generator = new EventGenerator(EnumSet.range(Event.SHELF_LOADED, Event.SHELF_MOVED_TO_TOP));

    void generateEvent(Event event) {
        generator.generateEvent(event);
    }

    void generateEvent(Event event, Shelf shelf) {
        generator.generateEvent(event, shelf);
    }

    void generateEvent(Event event, App app) {
        generator.generateEvent(event, app);
    }

    void generateEvent(Event event, Shelf shelf, App app) {
        shelf.getGenerator().generateEvent(event, app);
    }

    void generateEvent(Event event, Shelf shelf, List<App> apps) {
        shelf.getGenerator().generateEvent(event, apps);
    }

    ///

    void addListener(Event event, EventListener listener) {
        generator.addListener(event, listener);
    }

    void addListener(Shelf shelf, Event event, EventListener listener) {
        shelf.getGenerator().addListener(event, listener);
    }

    boolean isListenerSet(Event event) {
        return generator.isListenerSet(event);
    }

    void removeListener(Event event, EventListener listener) {
        generator.removeListener(event, listener);
    }

    void removeAllListeners() {
        generator.removeAllListeners();

        for (int i = 0; i < getAccessor().getRealShelvesNumber(); i++)
            getAccessor().getShelf(i).getGenerator().removeAllListeners();
    }

    ///

    static ModelEvents instance() {
        if (_instance == null)
            _instance = new ModelEvents();
        return _instance;
    }

}
